package ma.ensao.egicom.bank.services.model;

import java.util.Calendar;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import ma.ensao.egicom.bank.services.utils.OperationType;

import org.scub.foundation.framework.core.model.BaseModel;

/**
 * Entit� persistante modilisant une op�ration bancaire.
 * @author MILHI Yassine (milhi.yassinee@gmail.com)
 */
@Entity
@Table(name = "operation")
public class Operation extends BaseModel {
    private static final long serialVersionUID = 1648642991406224637L;

    @Column(nullable = false)
    private Calendar operationDate;

    @Column(nullable = false)
    private Double operationCost;

    @Column(nullable = false)
    private OperationType type;

    @ManyToOne(fetch = FetchType.LAZY)
    private CreditCard creditCard;

    public Operation(Calendar operationDate, Double operationCost, OperationType type, CreditCard creditCard) {
        this.operationDate = operationDate;
        this.operationCost = operationCost;
        this.type = type;
        this.creditCard = creditCard;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(Object other) {
        if (other == null || !(other instanceof Operation)) {
            return false;
        }
        return equalsUtil(other);
    }

    @Override
    public int hashCode() {
        return super.hashCode();
    }

    /**
     * Retourne la carte de cr&eacute;dit associ&eacute;e &agrave; cette op&eacute;ration.
     * @return la carte de cr&eacute;dit associ&eacute;e &agrave; cette op&eacute;ration
     */
    public CreditCard getCreditCard() {
        return creditCard;
    }

    /**
     * Modifie la carte de cr&eacute;dit associ&eacute;e &agrave; cette op&eacute;ration.
     * @param creditCard la carte de cr&eacute;dit associ&eacute;e &agrave; cette op&eacute;ration
     */
    public void creditCard(CreditCard creditCard) {
        this.creditCard = creditCard;
    }

    /**
     * Retourne la date de l'op&eacute;ration.
     * @return la date de l'op&eacute;ration
     */
    public Calendar getOperationDate() {
        return operationDate;
    }

    /**
     * Modifie la date de l'op&eacute;ration.
     * @param operationDate la date de l'op&eacute;ration
     */
    public void setOperationDate(Calendar operationDate) {
        this.operationDate = operationDate;
    }

    /**
     * Retourne la valeur mon&eacute;tique de la commande.
     * @return la valeur mon&eacute;tique de la commande
     */
    public Double getOperationCost() {
        return operationCost;
    }

    /**
     * Modifie la valeur mon&eacute;tique de la commande.
     * @param operationCost la valeur mon&eacute;tique de la commande
     */
    public void setOperationCost(Double operationCost) {
        this.operationCost = operationCost;
    }

    /**
     * Retourne le type de l'op&eacute;ration eff&eacute;ctu&eacute;e.
     * @return le type de l'op&eacute;ration eff&eacute;ctu&eacute;e.
     */
    public OperationType getType() {
        return type;
    }

    /**
     * Modifie le type de l'op&eacute;ration eff&eacute;ctu&eacute;e.
     * @param type le type de l'op&eacute;ration eff&eacute;ctu&eacute;e.
     */
    public void setType(OperationType type) {
        this.type = type;
    }

}
